package com.marvels.approve.common.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.marvels.approve.common.service.ApproveSharedDataService;
import com.marvels.common.utils.HttpUtils;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.common.utils.ServerProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class ApproveSharedDataImpl implements ApproveSharedDataService{
	
	@Value("${config.properties.path}")
	private String configPropertiesPath;
	
	@Override
	public Map<String, Object> sharedDataQuery(Map<String, Object> map) {
		String sharedDataRequestUrl=ServerProperties.getValue(configPropertiesPath, "common.properties", "shared_data_request_url");
		Map<String, Object> resultMap=new HashMap<String, Object>();
		String result="";
		try {
			result=HttpUtils.httpPost(sharedDataRequestUrl, JSON.toJSONString(map));
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>共享数据查询异常:",e);
			return null;
		}
		JSONObject jsonObject = JSONObject.parseObject(result);
		if(jsonObject != null && !jsonObject.isEmpty()){
			MarvelsLogUtil.getInstance().info(">>>>>共享数据查询返回结果:"+jsonObject.toString());
			for(String key:jsonObject.keySet()){
				resultMap.put(key, jsonObject.get(key));
			}
		}
		return resultMap;
	}

}
